import datetime
import sys
import os
import threading

from gui.entrance import *
from PyQt5.QtWidgets import QApplication
from PyQt5 import QtCore
from reptile.obtain import Reptile, Cloud

if __name__ == "__main__":
    QtCore.QCoreApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling)
    app = QApplication(sys.argv)
    loader = LoaderWindow()
    work_dir = os.path.abspath('.')
    path = work_dir + r'\reptile'
    if datetime.datetime.now().day % 2 == 0 and datetime.datetime.now().hour % 2 == 0:
        fun = lambda: (
            Reptile.get(path + r'\text.txt'),
            Cloud.draw(text_path=path + r'\text.txt', pic_path=path + r'\background.png',
                       save_path=path + r'\word_cloud.png'))
        thread_reptile = threading.Thread(target=fun)
        thread_reptile.start()
    loader.show()
    sys.exit(app.exec_())
